﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication8
{
    public partial class About : System.Web.UI.Page
    {
        //struct obrazec
        //{
        //    public System.Xml.XmlNode nastavitev_node;
        //    public Label nastavitev_label_name;
        //    public TextBox nastavitev_txtbox_min;
        //    public TextBox nastavitev_txtbox_max;

        //    public obrazec(System.Xml.XmlNode _nastavitev_node, Label _nastavitev_label_name, TextBox _nastavitev_txtbox_min, TextBox _nastavitev_txtbox_max)
        //    {
        //        nastavitev_node = _nastavitev_node;
        //        nastavitev_label_name = _nastavitev_label_name;
        //        nastavitev_txtbox_min = _nastavitev_txtbox_min;
        //        nastavitev_txtbox_max = _nastavitev_txtbox_max;
        //    }
        //}

        //List<obrazec> obrazc = new List<obrazec>();
        System.Xml.XmlDocument setting = new System.Xml.XmlDocument();

        //System.Xml.XmlNode nastavitve_t;
        System.Xml.XmlNode nastavitve_logging;
        System.Xml.XmlNode nastavitve_profili;

        protected void Page_Load(object sender, EventArgs e)
        {

            setting.Load(Request.PhysicalApplicationPath + "settings.xml");

            nastavitve_logging = setting.SelectSingleNode("/regulator/nastavitve/sistem");
            nastavitve_profili = setting.SelectSingleNode("/regulator/nastavitve/profili");

            Table tabela = new Table();
            //obrazc.Clear();


            // LOGIRANJE NASTAVITVE
            if (!IsPostBack)
            {
                if (nastavitve_logging.Attributes.GetNamedItem("logging").Value == "0")
                    CheckBox1.Checked = false;
                else
                    CheckBox1.Checked = true;
                TextBox1.Text = nastavitve_logging.Attributes.GetNamedItem("logging_file").Value;
            }

            //PROFILI
            if (!IsPostBack)
            {
                DropDownList1.Items.Add("- Izberi -");
                foreach (System.Xml.XmlNode profil in nastavitve_profili.ChildNodes)
                {
                    ListItem neki = new ListItem(profil.Name, profil.BaseURI);
                    DropDownList1.Items.Add(neki);
                }
                DropDownList1.Items.Add("- Nov -");
            }




        }

        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    float a; 
        //    foreach (obrazec x in obrazc)
        //    {
        //        x.nastavitev_node.Attributes.GetNamedItem("name").Value = x.nastavitev_label_name.Text;
        //        if (float.TryParse(x.nastavitev_txtbox_min.Text, out a))
        //            x.nastavitev_node.Attributes.GetNamedItem("min").Value = x.nastavitev_txtbox_min.Text;
        //        else
        //            x.nastavitev_txtbox_min.Text = "-ERR-";
        //        if (float.TryParse(x.nastavitev_txtbox_max.Text, out a))
        //            x.nastavitev_node.Attributes.GetNamedItem("max").Value = x.nastavitev_txtbox_max.Text;
        //        else
        //            x.nastavitev_txtbox_max.Text = "-ERR-";
        //    }
        //    setting.Save(Request.PhysicalApplicationPath + "settings.xml");
        //}

        protected void Button2_Click(object sender, EventArgs e)
        {

            if (CheckBox1.Checked)
                nastavitve_logging.Attributes.GetNamedItem("logging").Value = "1";
            else
                nastavitve_logging.Attributes.GetNamedItem("logging").Value = "0";
            nastavitve_logging.Attributes.GetNamedItem("logging_file").Value = TextBox1.Text;
            nastavitve_logging.OwnerDocument.Save(Request.PhysicalApplicationPath + "settings.xml");

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

            foreach (System.Xml.XmlNode profil in nastavitve_profili.SelectSingleNode(DropDownList1.SelectedItem.Text))
            {
                
            }
        }
    }
}
